package com.healthcarex.hip.saas.security.service.impl;

import com.healthcarex.hip.saas.security.model.SysUserRole;
import com.healthcarex.hip.saas.security.service.IUserRoleService;
import com.healthcarex.hip.saas.mybatis.service.impl.BaseServiceImpl;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.Arrays;
import java.util.List;

/**
 * @author chenpan
 * @ClassName: UserRoleServiceImpl
 * description:
 * @date 2018-04-02 17:38
 */
@Service
public class UserRoleServiceImpl extends BaseServiceImpl<SysUserRole> implements IUserRoleService {

    @Override
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
    @CacheEvict(value = "authority", allEntries = true)
    public void deleteUserRolesByRoleId(String roleIds) {
        List<String> list = Arrays.asList(roleIds.split(","));
        this.batchDelete(list, "roleId", SysUserRole.class);
    }

    @Override
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true, rollbackFor = Exception.class)
    @CacheEvict(value = "authority", allEntries = true)
    public void deleteUserRolesByUserId(String userIds) {
        List<String> list = Arrays.asList(userIds.split(","));
        this.batchDelete(list, "userId", SysUserRole.class);
    }
}
